//
//  CourseCenterCartCell.m
//  xpkc
//
//  Created by TopSageOSX on 14/12/22.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "CourseCenterCartCell.h"

@implementation CourseCenterCartCell

- (void)awakeFromNib {
    // Initialization code
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}

- (void)creatCell{
    self.tintColor = UIColorFromRGB(0xff4e4e);
    //creat ff4e4e
    self.itemImg = [[UIImageView alloc]init];
    self.itemTitle = [[UILabel alloc]init];
    self.itemIntroduction = [[UILabel alloc]init];
    self.itemOriginalPrice = [[UILabel alloc]init];
    UIView *priceline = [[UIView alloc]init];
    self.itemPrice = [[UILabel alloc]init];
    
    //位置
    CGRect img_frame;
    CGRect title_label_frame;
    CGRect introduction_label_frame;
    CGRect oroprice_label_frame,priceline_frame;
    CGRect price_label_frame;
    CGRect delet_btn_frame;
    NSString *vb = @"5";
    NSArray *ar = @[vb];
    id vv = [ar objectAtIndex:0];
    [vv intValue];
    
    CGFloat offwidth = 0.04*SCREEN_WIDTH;
    CGFloat imgwidth = 0.25*SCREEN_WIDTH;
    CGFloat titlewidth = 0.8*SCREEN_WIDTH;
    CGFloat pricewidth = 0.2*SCREEN_WIDTH;
    CGFloat btnwidth = 0.06*SCREEN_WIDTH;
    img_frame = CGRectMake(offwidth, offwidth, imgwidth, imgwidth*0.8);
    title_label_frame = CGRectMake(offwidth, offwidth*0.5, titlewidth, 45);
    introduction_label_frame = CGRectMake(offwidth, offwidth*0.5+40, titlewidth, 80-offwidth*0.5-40);
    oroprice_label_frame  = CGRectMake(offwidth+titlewidth, offwidth*0.5, pricewidth, 30);
    priceline_frame = CGRectMake(offwidth+imgwidth+titlewidth, offwidth*0.5+15, pricewidth, 1);
    price_label_frame = CGRectMake(SCREEN_WIDTH - pricewidth - 60, offwidth*0.5+30,100, 30);
    delet_btn_frame = CGRectMake(SCREEN_WIDTH-btnwidth, 50-btnwidth, btnwidth, btnwidth*2);
    
    self.itemImg.frame = img_frame;
    self.itemTitle.frame = title_label_frame;
    self.itemIntroduction.frame = introduction_label_frame;
    self.itemOriginalPrice.frame = oroprice_label_frame;
    priceline.frame = priceline_frame;
    self.itemPrice.frame = price_label_frame;
//    self.itemPrice.backgroundColor = [UIColor redColor];
    
    
    //详细
    self.itemImg.layer.shadowColor = [UIColor blackColor].CGColor;
    self.itemImg.layer.shadowOpacity = 0.3;
    self.itemImg.image = [UIImage imageNamed:@"5C71F048-5A9A-4A18-A065-8AA2F802E3DD"];
    
    self.itemTitle.numberOfLines = 0;
    self.itemTitle.font = FONT_SYS_M;
    
    self.itemIntroduction.numberOfLines = 0;
    self.itemIntroduction.textColor = [UIColor lightGrayColor];
    self.itemIntroduction.font = FONT_SYS_S;
    
    self.itemOriginalPrice.textColor = [UIColor lightGrayColor];
    self.itemOriginalPrice.font = FONT_SYS_XS;
    
    priceline.layer.borderWidth = 1;
    priceline.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    self.itemPrice.textColor = [UIColor redColor];
    self.itemPrice.font = FONT_SYS_M;
    
    
    //添加
    //    [self addSubview:self.itemImg];
    [self.contentView addSubview:self.itemTitle];
    [self.contentView addSubview:self.itemIntroduction];
    //    [self addSubview:self.itemOriginalPrice];
    //    [self addSubview:priceline];
    [self.contentView addSubview:self.itemPrice];
    
    
    
     // price_label_frame = CGRectMake(SCREEN_WIDTH - pricewidth - 60, offwidth*0.5+30,100, 30);
    
    // 赠品
    self.giftView = [[UIView alloc] init];
    [self.contentView addSubview:self.giftView];
    
    
    self.lineLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.lineLabel];
    
}

-(void)configWithArray:(NSArray *)giftArray{
    CGFloat offwidth = 0.04*SCREEN_WIDTH;
    CGFloat titlewidth = 0.8*SCREEN_WIDTH;
    CGFloat pricewidth = 0.2*SCREEN_WIDTH;
    
    //  CGRectMake(SCREEN_WIDTH - pricewidth - 60, offwidth*0.5+30,100, 30);
   //  title_label_frame = CGRectMake(offwidth, offwidth*0.5, titlewidth, 45);
    self.giftView.frame = CGRectMake(0, offwidth*0.5+30+ 30,SCREEN_WIDTH, giftArray.count * 60);
    
    NSArray * views = self.giftView.subviews;
    
    for (UIView * view in views) {
        [view removeFromSuperview];
    }
    int i = 0;
    for (NSDictionary * dict in giftArray) {
        
        
        // 赠品
        UILabel * wardLabel = [[UILabel alloc] initWithFrame:CGRectMake(offwidth , offwidth * 0.5 + 50 * i, 40, 45)];
        wardLabel.text = @"赠";
        wardLabel.font = [UIFont systemFontOfSize:16];
        wardLabel.textColor = [UIColor redColor];
        [self.giftView addSubview:wardLabel];
        
        // 赠品名称
        UILabel * goodNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(offwidth + 40 , offwidth * 0.5 + 50 * i, titlewidth - 50, 45)];
        goodNameLabel.text = dict[@"name"];
        goodNameLabel.font = [UIFont systemFontOfSize:14];
        goodNameLabel.numberOfLines = 0;
        [self.giftView addSubview:goodNameLabel];
        
        
        // 赠品价格
        UILabel * goodPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - pricewidth - 60, offwidth * 0.5 + 30  + 50 * i, 100, 30)];
        goodPriceLabel.text = dict[@"trueprice"];
        goodPriceLabel.font = [UIFont systemFontOfSize:14];
        goodPriceLabel.textColor = [UIColor redColor];
        [self.giftView addSubview:goodPriceLabel];
        
        i ++;
    }
    

    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
